﻿CREATE TABLE [dbo].[Stocuri] (
    [IDStoc]            INT             IDENTITY (1, 1) NOT NULL,
    [IDArticol]         INT             NOT NULL,
    [CodUnitate]        SMALLINT        NOT NULL,
    [Pret]              DECIMAL (25, 5) DEFAULT ((0)) NOT NULL,
    [StocInitial]       DECIMAL (25, 5) DEFAULT ((0)) NOT NULL,
    [StocPrecedent]     DECIMAL (25, 5) DEFAULT ((0)) NOT NULL,
    [IDDepartament]     INT             NULL,
    [IDVarinataArticol] INT             NULL,
    [DataIntrare]       DATETIME        DEFAULT (getdate()) NOT NULL,
    [PretValuta]        DECIMAL (25, 5) DEFAULT ((0)) NOT NULL,
    [PretCodValuta]     SMALLINT        DEFAULT ((0)) NOT NULL,
    [Intrari]           AS              ([dbo].[GetStocIntrari]([IDArticol],[Pret])),
    [Iesiri]            AS              ([dbo].[GetStocIesiri]([CodUnitate],[IDArticol],[Pret])),
    CONSTRAINT [PK_Stocuri] PRIMARY KEY CLUSTERED ([IDStoc] ASC),
    CONSTRAINT [FK_Stocuri_Articole] FOREIGN KEY ([IDArticol]) REFERENCES [dbo].[Articole] ([IDArticol]),
    CONSTRAINT [FK_Stocuri_ArticoleVariante] FOREIGN KEY ([IDVarinataArticol]) REFERENCES [dbo].[ArticoleVariante] ([IDVariantaArticol]),
    CONSTRAINT [FK_Stocuri_Departamente] FOREIGN KEY ([IDDepartament]) REFERENCES [dbo].[Departamente] ([IDDepartament]),
    CONSTRAINT [FK_Stocuri_Unitati] FOREIGN KEY ([CodUnitate]) REFERENCES [dbo].[Unitati] ([CodUnitate]),
    CONSTRAINT [FK_Stocuri_Valuta] FOREIGN KEY ([PretCodValuta]) REFERENCES [dbo].[Valuta] ([CodValuta])
);

